package Notes;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.FlowLayout;

import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.util.Arrays;
import java.awt.Dimension;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

public class Lotto_Jint extends JFrame {

	private JPanel contentPane;
	private JLabel first;
	private JLabel second;
	private JLabel third;
	private JLabel forth;
	private JLabel fifth;
	private JLabel sixth;	
	private JButton button;
	int[] lo = new int[6];
	
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Lotto_Jint frame = new Lotto_Jint();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}				
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Lotto_Jint() {
		
		
		
		
		setTitle("LOTTO Program");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 450);
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(111)
					.addComponent(getFirst())
					.addGap(5)
					.addComponent(getSecond())
					.addGap(5)
					.addComponent(getThird())
					.addGap(5)
					.addComponent(getForth())
					.addGap(5)
					.addComponent(getFifth())
					.addGap(5)
					.addComponent(getSixth())
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(getButton(), GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGap(111))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(5)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(getFirst())
								.addComponent(getSecond())
								.addComponent(getThird())
								.addComponent(getForth())
								.addComponent(getFifth())
								.addComponent(getSixth())))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(getButton(), GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addGap(7)))
					.addGap(362))
		);
		contentPane.setLayout(gl_contentPane);
	}

	private JLabel getFirst() {
		if (first == null) {
			first = new JLabel("L");
			first.setForeground(Color.RED);
			first.setFont(new Font("굴림", Font.PLAIN, 30));
		}
		return first;
	}
	private JLabel getSecond() {
		if (second == null) {
			second = new JLabel("O");
			second.setForeground(Color.ORANGE);
			second.setFont(new Font("굴림", Font.PLAIN, 30));
		}
		return second;
	}
	private JLabel getThird() {
		if (third == null) {
			third = new JLabel("T");
			third.setForeground(new Color(0, 100, 0));
			third.setFont(new Font("굴림", Font.PLAIN, 30));
		}
		return third;
	}
	private JLabel getForth() {
		if (forth == null) {
			forth = new JLabel("T");
			forth.setForeground(new Color(148, 0, 211));
			forth.setFont(new Font("굴림", Font.PLAIN, 30));
		}
		return forth;
	}
	private JLabel getFifth() {
		if (fifth == null) {
			fifth = new JLabel("O");
			fifth.setForeground(new Color(128, 0, 0));
			fifth.setFont(new Font("굴림", Font.PLAIN, 30));
		}
		return fifth;
	}
	private JLabel getSixth() {
		if (sixth == null) {
			sixth = new JLabel("S");
			sixth.setForeground(new Color(135, 206, 250));
			sixth.setFont(new Font("굴림", Font.PLAIN, 30));
		}
		return sixth;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("Start");
			button.setMaximumSize(new Dimension(20, 23));
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					for(int i=0;i<lo.length;i++){
						lo[i]=(int)(Math.random()*45+1);
						for(int j=0;j<i;j++){
							if(lo[j]==lo[i]) i=0;
						}
					}
					Arrays.sort(lo);
					first.setText(String.valueOf(lo[0]));
					second.setText(String.valueOf(lo[1]));
					third.setText(String.valueOf(lo[2]));
					forth.setText(String.valueOf(lo[3]));
					fifth.setText(String.valueOf(lo[4]));
					sixth.setText(String.valueOf(lo[5]));
				}
			});
		}
		return button;
	}
}
